<script setup lang="ts" name="SystemMyNotifyDetail">
import { DICT_TYPE } from '@/enums/dictEnums'
import { MyNotifyType } from '@/api/system/messages/notify/my'
import { formatDate } from '@/utils/dateUtil'

const { t } = useI18n() // 国际化
const visible = ref(false) // 弹窗的是否展示
const detailLoading = ref(false) // 表单的加载中
const detailData = ref({} as MyNotifyType) // 详情数据

/** 打开弹窗 */
const open = async (data: MyNotifyType) => {
  visible.value = true
  // 设置数据
  detailLoading.value = true
  try {
    detailData.value = data
  } finally {
    detailLoading.value = false
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<template>
  <Dialog v-model="visible" :title="t('sys.messages.notify.my', 'detail')" height="320px" type="scroll" width="800px">
    <el-descriptions v-if="detailData" :column="1" border class="mr-10px">
      <el-descriptions-item :label="t('sys.messages.notify.my', 'templateNickname')">
        {{ detailData.templateNickname }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.notify.my', 'sendTime')">
        {{ formatDate(detailData.create_time!) }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.notify.my', 'templateType')">
        <dict-tag :type="DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE" :value="detailData.templateType" />
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.notify.my', 'readStatus')" min-width="120">
        <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="detailData.readStatus" />
      </el-descriptions-item>
      <el-descriptions-item v-if="detailData.readStatus" :label="t('sys.messages.notify.my', 'readTime')">
        {{ formatDate(detailData.readTime) }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.notify.my', 'templateContent')">
        <div v-html="detailData.templateContent" />
      </el-descriptions-item>
    </el-descriptions>
  </Dialog>
</template>

<style scoped lang="scss"></style>
